package com.lhz.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.lhz.pojos.User;
import com.lhz.services.UserService;

@Controller
@RequestMapping("/user")
public class UserControll {

	@Autowired
	private UserService userseivice;

	
	 /**
	  * 查询所有会员
	  * @param mv
	  * @return
	  */
	@RequestMapping(value="/userManage")
	public ModelAndView huiyuanguanli(
			@RequestParam(value="pageNow",required=false,defaultValue="1") int pageNow,
			@RequestParam(value="pageSize",required=false,defaultValue="10") int pageSize ,
			User usre) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> userall = userseivice.useralls(usre,pageNow,pageSize);
 		mv.addObject("userall",userall);
		mv.setViewName("UserManage");
		return  mv;
	}
	
	/**
	 * 用户手机查找
	 * @param phone
	 * @param mv
	 * @return
	 */
	@RequestMapping(value="/userinfo",method=RequestMethod.POST)
	public ModelAndView userinfoall(
			@RequestParam(value="pageNow",required=false,defaultValue="1") int pageNow,
			@RequestParam(value="pageSize",required=false,defaultValue="10") int pageSize ,
			Long phone) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> userInfo = userseivice.userIndoall(pageNow,pageSize,phone);
		mv.addObject("userall",userInfo);
		mv.setViewName("UserManage");
		return mv;
	}
	
	/**
	 * 根据日期条件查询
	 * @param mv
	 * @return
	 */
	@RequestMapping(value="/userinfodate")
	public ModelAndView userInfodate(
	@RequestParam(value="pageNow",required=false,defaultValue="1") int pageNow,
	@RequestParam(value="pageSize",required=false,defaultValue="10") int pageSize ,
	String startTime,String endTime) {
	ModelAndView mv=new ModelAndView();
	Map<String, Object> userinfo = userseivice.userInfodate(pageNow, pageSize, startTime, endTime);
	mv.addObject("userall", userinfo);
	mv.setViewName("UserManage");
		return mv;
	}
	
	/**
	 * 查看状态
	 * @param status
	 * @param pageNow
	 * @param pageSize
	 * @param mv
	 * @return
	 */
	@RequestMapping(value="/userInstatus")
	public ModelAndView userInstatus(
			@RequestParam(value="pageNow",required=false,defaultValue="1") int pageNow,
			@RequestParam(value="pageSize",required=false,defaultValue="10") int pageSize ,
			Integer status) {
		ModelAndView mv=new ModelAndView();
		System.out.println(status);
		Map<String, Object> userinfo = userseivice.userInstatus(pageNow,pageSize,status);
		mv.addObject("userall", userinfo);
		mv.setViewName("UserManage");
 		return mv;
	}
	
	
	
	/**
	 * 设置用户状态
	 * @param status
	 * @param phone
	 * @return
	 */
	@RequestMapping(value="/userselect")
	@ResponseBody
	public Map<String,String> userselect(String status,String phone) {
		return userseivice.userselectstatus(status,phone);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
